#-*- coding:UTF-8 -*-
'''
Created on 2012-7-18
Mail Opter
@author: Administrator
'''
from smtplib import SMTP
from poplib import POP3
from time import sleep

SMTPSVR = 'mail.unissoft-gov.com'
POPSVR = 'mail.unissoft-gov.com'
MAILNAME = ''
MAILPASSWORD = 'gaoping123456'

origHdrs = ['From:gaoping@unissoft-gov.com',
             'To:songxingming@unissoft-gov.com,gaoping@unissoft-gov.com',
             'Subject:Python send mail test']
origBody = ['xxx', 'yyyy', 'zzzz']
origMsg = '\r\n\r\n'.join(['\r\n'.join(origHdrs), '\r\n'.join(origBody)])

def sendMail():
    sendSvr = SMTP(SMTPSVR)
    #登录
    sendSvr.login('gaoping@unissoft-gov.com', 'gaoping123456')
    print '登录成功'
    errs = sendSvr.sendmail('gaoping@unissoft-gov.com', ('gaoping@unissoft-gov.com', 'songxingming@unissoft-gov.com'),
                            origMsg)
    sendSvr.quit()
    assert len(errs) == 0, errs
    print '发送Mail成功'

def acceptMail():
    recvSvr = POP3(POPSVR)
    recvSvr.user('gaoping@unissoft-gov.com')
    recvSvr.pass_('gaoping123456')
    rsp, msg, siz = recvSvr.retr(recvSvr.stat()[0])
    sep = msg.index('')
    recvBody = msg[sep + 1:]
    assert origBody == recvBody
    print '邮件内容:', recvBody

if __name__ == '__main__':
    sendMail()
    sleep(10)
    acceptMail()
